# NEVER EDIT this file.  It was generated and will be overwritten without
# notice upon regeneration of this application.  You have been warned.
package StopTrack::GEN::Lot;

use strict;

use base 'StopTrack';

use StopTrack::Model::lot qw(
    $LOT
);
use Gantry::Plugins::Calendar qw(
    do_calendar_month
    calendar_month_js
);



#-----------------------------------------------------------------
# $self->do_main(  )
#-----------------------------------------------------------------
sub do_main {
    my ( $self ) = @_;

    $self->stash->view->template( 'results.tt' );
    $self->stash->view->title( 'Lot' );

    my $real_location = $self->location() || '';
    if ( $real_location ) {
        $real_location =~ s{/+$}{};
        $real_location .= '/';
    }

    my $retval = {
        headings       => [
            'Bought',
            'Paid',
        ],
        header_options => [
            {
                text => 'Add',
                link => $real_location . "add",
            },
        ],
    };

    my $schema = $self->get_schema();
    my @rows   = $LOT->get_listing( { schema => $schema } );

    foreach my $row ( @rows ) {
        my $id = $row->id;
        push(
            @{ $retval->{rows} }, {
                data => [
                    $row->bought,
                    $row->paid,
                ],
                options => [
                    {
                        text => 'Edit',
                        link => $real_location . "edit/$id",
                    },
                    {
                        text => 'Delete',
                        link => $real_location . "delete/$id",
                    },
                ],
            }
        );
    }

    $self->stash->view->data( $retval );
} # END do_main

#-----------------------------------------------------------------
# $self->form( $row )
#-----------------------------------------------------------------
sub form {
    my ( $self, $row ) = @_;

    my $selections = $LOT->get_form_selections(
            { schema => $self->get_schema() }
    );

    return {
        name       => 'lot',
        row        => $row,
        legend => $self->path_info =~ /edit/i ? 'Edit' : 'Add',
        javascript => $self->calendar_month_js( 'lot' ),
        fields     => [
            {
                date_select_text => 'Select Date',
                name => 'bought',
                label => 'Bought',
                type => 'text',
                is => 'date',
            },
            {
                name => 'paid',
                label => 'Paid',
                type => 'text',
                is => 'int4',
            },
            {
                options => $selections->{stock},
                name => 'stock',
                label => 'Stock',
                type => 'select',
                is => 'int4',
            },
            {
                name => 'shares',
                label => 'Shares',
                type => 'text',
                is => 'int4',
            },
        ],
    };
} # END form


1;

=head1 NAME

StopTrack::GEN::Lot - generated support module for StopTrack::Lot

=head1 SYNOPSIS

In StopTrack::Lot:

    use StopTrack::GEN::Lot qw(
        do_main
        form
    );

=head1 DESCRIPTION

This module was generated by bigtop and IS subject to regeneration.
Use it in StopTrack::Lot to provide the methods below.
They are exported by default.

=head1 METHODS

=over 4

=item do_main

=item form


=back

=head1 AUTHOR

Generated by bigtop and subject to regeneration.

=cut

